import * as React from 'react';
import { Icon, Button } from 'antd';

export function getPanelOptions(editId: number, tagName: string, options: any = {}) {
  let addButton = null;

  if (editId && options['addButton']) {
    addButton = (
      <Button
        className="add-button"
        size="small"
        icon="plus"
        type="primary"
        onClick={(e: any) => {
          options.onAdd();

          e.preventDefault();
          e.stopPropagation();
        }}
      />
    );
  }

  const header = (
    <p>
      {options['notMust'] === true ? null : <label className="ant-form-item-required" />}
      {tagName}
      &nbsp;
      {editId ? '' : <Icon type="lock" />}
      {addButton}
    </p>
  );
  const disabled = !editId;
  const className = editId ? '' : 'disable-open';
  const key = options['key'] || tagName.toLowerCase();

  return {
    header,
    className,
    key,
    disabled,
  };
}
